package arch.dao.impl.archive;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import arch.domain.archive.Stamp;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class StampAssignmentBatchPreparedStatementSetter implements
		BatchPreparedStatementSetter {
	private Stamp stamp;
	public StampAssignmentBatchPreparedStatementSetter(Stamp stamp) {
		this.stamp = stamp;
	}
	public int getBatchSize() {
		return this.stamp.getFields().size();
	}
	public void setValues(PreparedStatement pstmt, int i) throws SQLException {
		if(stamp.getId() != null) {
			pstmt.setInt(1, this.stamp.getId());
		} else {
			pstmt.setNull(1, Types.NULL);
		}
		if(stamp.getFields() != null && stamp.getFields().get(i) != null && stamp.getFields().get(i).getId() != null) {
			pstmt.setInt(2, this.stamp.getFields().get(i).getId());
		} else {
			pstmt.setNull(2, Types.NULL);
		}
	}

}
